package Internal_Anonymity;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
 * @Description:内部类演示实验
 * @Author:AMark
 * @Date: 10/23/2023
 */
public class InternalDemo {
    private JFrame frame;
    private JButton okB,cancelB;
    InternalDemo(String title) {
        frame = new JFrame(title);
        frame.setSize(260, 150);
        frame.setLayout(new FlowLayout());
        okB = new JButton("确定");
        cancelB = new JButton("取消");
        frame.add(okB);
        frame.add(cancelB);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ButtonEvent buttonEvent = new ButtonEvent();
        okB.addActionListener(buttonEvent);
        cancelB.addActionListener(buttonEvent);
    }
    class ButtonEvent implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == okB){
                frame.setTitle("OK");
            } else if (e.getSource() == cancelB) {
                frame.setTitle("Cancel");
            }
        }
    }
    public static void main(String[] args) {
        InternalDemo ID = new InternalDemo("HelloInternal");
    }
}
